﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using GS.CMS.Entities;
using GS.Config;

public partial class usercontrols_upcommingproduct : System.Web.UI.UserControl
{
    DataTable dtUpcommingProduct;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            BindData();
    }
    public DataTable UpcommingProduct
    {
        set
        {
            dtUpcommingProduct = value;
        }
    }
    /// <summary>
    /// Lấy dữ liệu bind lên control DataList
    /// </summary>
    private void BindData()
    {
        try
        {
            dtlProducts.DataSource = dtUpcommingProduct;
            dtlProducts.DataBind();
        }
        catch (Exception ex)
        {
            TrackingError.AddTrackingError("Author: sanghv - Funtion: BindData - Usercontrol:usercontrols_statusproducts", ex.Message);
        }
    }
    protected string LinkImage(object ImgPath, object ProductID, object NameProduct, object CategoryID, object Description)
    {
        string html = "";
        if (ImgPath != DBNull.Value && Description != DBNull.Value)
        {
            html += string.Format("<a href=\"product-detail.aspx?subcat={2}&pid={0}\" onmouseover=\"ddrivetip('{1} |{2}| {3}')\" onmouseout=\"hideddrivetip()\"><img alt=\"\"  src=\"{4}/{5}\" style=\"border:none\" height=\"112\" width=\"210\" /></a>",
                                   ProductID, NameProduct, CategoryID, Description, Config.IamgeProduct, ImgPath);
        }
        return html;
    }
    protected string LinkHeader(object ProductID, object Name, object CategoryID)
    {
        string html = "";
        if (Name != DBNull.Value)
        {
            html += string.Format(@"<a href='product-detail.aspx?subcat={0}&pid={1}' >{2}</a>",
                                  CategoryID, ProductID, Name);
        }
        return html;
    }
    protected string Price(object Price, object IsMapPrice, object Discount)
    {
        string html = "";
        //Nếu có discount và Không phải là MapPirce
        if (Discount != DBNull.Value && (int)Discount > 0 && (bool)IsMapPrice == false)
        {
            if (Price != DBNull.Value)
            {
                decimal price = Convert.ToDecimal(Price);
                decimal truePrice = price - (price * (int)Discount / 100);
                string[] arrPrice = truePrice.ToString("C").Split('.');
                html += string.Format("<div class=\"discount-price\"><span class=\"old-price\">{0}</span> <br/> <span class=\"new-price\">{1}<sup>.{2}</sup></span></div>",
                    price.ToString("C"), arrPrice[0], arrPrice[1]);
            }
        }
        else if ((bool)IsMapPrice == true)
        {
            if (Price != DBNull.Value)
            {
                decimal price = Convert.ToDecimal(Price);
                string[] arrPrice = price.ToString("C").Split('.');
                html += string.Format("<div class=\"map-price\">Map price <br/>{0}<sup>.{1}</sup></div>", arrPrice[0], arrPrice[1]);
            }
        }
        else if (Discount == DBNull.Value || (int)Discount == 0)
        {
            if (Price != DBNull.Value)
            {
                decimal price = Convert.ToDecimal(Price);
                string[] arrPrice = price.ToString("C").Split('.');
                html += string.Format("<div class=\"price\">{0}<sup>.{1}</sup></div>", arrPrice[0], arrPrice[1]);
            }
        }
        return html;
    }
}